package com.eqdd.yiqidian.ui.discover;

import android.databinding.DataBindingUtil;
import android.graphics.Color;
import android.support.v7.widget.CardView;
import android.support.v7.widget.GridLayoutManager;
import android.view.View;

import com.coorchice.library.SuperTextView;
import com.eqdd.yiqidian.QiyeBlankActivityCustom;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.adapter.slimadapter.SlimAdapterEx;
import com.eqdd.yiqidian.adapter.slimadapter.SlimInjector;
import com.eqdd.yiqidian.adapter.slimadapter.viewinjector.IViewInjector;
import com.eqdd.yiqidian.base.BaseActivity;

import java.util.ArrayList;
import java.util.Date;
import java.util.Random;

public class QiyeBlankActivity extends BaseActivity {
    private QiyeBlankActivityCustom dataBinding;
    private ArrayList<KanbanItem> kanbanItems;

    @Override
    public void initBinding() {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_qiye_blank);
        initTopTitleBar(View.VISIBLE, "企业看板");
    }

    @Override
    public void initData() {
        kanbanItems = new ArrayList<>();
        kanbanItems.add(new KanbanItem("执行达成率", R.mipmap.zhxdacheng));
        kanbanItems.add(new KanbanItem("执行龙虎榜", R.mipmap.zhxlonghu));
        kanbanItems.add(new KanbanItem("绩效达成率", R.mipmap.jxdacheng));
        kanbanItems.add(new KanbanItem("绩效龙虎榜", R.mipmap.jxlonghu));
        kanbanItems.add(new KanbanItem("执行我最强", R.mipmap.zhxbang));
        kanbanItems.add(new KanbanItem("执行我加油", R.mipmap.zhxjiayou));
        kanbanItems.add(new KanbanItem("绩效我最棒", R.mipmap.jxbang));
        kanbanItems.add(new KanbanItem("绩效我加油", R.mipmap.jxjiayou));
        kanbanItems.add(new KanbanItem("任务展示", R.mipmap.zhanshi));
        kanbanItems.add(new KanbanItem("考勤排名", R.mipmap.kaoqin_pm));
    }

    @Override
    public void setView() {
        Random random = new Random(new Date().getTime());

        dataBinding.recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
        SlimAdapterEx slimAdapterEx = SlimAdapterEx.create().register(R.layout.list_item_17, new SlimInjector<KanbanItem>() {
            @Override
            public void onInject(KanbanItem data, IViewInjector injector) {
                injector.with(R.id.stv_title, v -> {
                            ((SuperTextView) v).setText(data.getTitle());
                            ((SuperTextView) v).setDrawable(getDrawable(data.getResId()));
                        }
                )
                        .with(R.id.cv_root, v ->
                            ((CardView) v).setCardBackgroundColor(
                                    Color.rgb(random.nextInt(255), random.nextInt(255), random.nextInt(255))));
            }
        }).attachTo(dataBinding.recyclerView);
        slimAdapterEx.updateData(kanbanItems);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()) {

        }
    }

    class KanbanItem {
        String title;
        int resId;

        public KanbanItem(String title, int resId) {
            this.title = title;
            this.resId = resId;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public int getResId() {
            return resId;
        }

        public void setResId(int resId) {
            this.resId = resId;
        }
    }
}
